using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VOL.Core.Extensions;
using VOL.Core.ManageUser;
using VOL.Core.Utilities;
using VOL.Entity.DomainModels;
using VOL.Entity.DomainModels.EvaluateNurseCare;
using VOL.SmartMecial.Dtos;
using VOL.SmartMecial.Infrastructure;
using VOL.SmartMecial.IServices.DoctorManage;

namespace VOL.SmartMecial.Services.DoctorManage
{
    public class TellManageService : ITellManageService
    {
        private readonly IBaseRepository<TellModel> _tellRepository;
        private readonly IBaseRepository<Patient> _patientRepository;

        public TellManageService(IBaseRepository<TellModel> tellRepository, IBaseRepository<Patient> patientRepository)
        {
            this._tellRepository = tellRepository;
            this._patientRepository = patientRepository;
        }

        public async Task<WebResponseContent> AddTell(TellModel tellModel)
        {
            int count = await _tellRepository.AddAsync(tellModel);
            if (count == 0)
            {
                var response = WebResponseContent.Instance.Error("添加失败");
                return response;
            }
            return WebResponseContent.Instance.OK("添加成功", count);

        }

        public async Task<WebResponseContent> GetTellList(string? patientName)
        {
            var dtoList = from t in _tellRepository.GetAll()
                          join p in _patientRepository.GetAll()
                          on t.PatientCode equals p.PatientCode
                          where t.IsDelete == 0
                          select new SearchTellListDto
                          {
                              Id = t.Id,
                              DoctorSTime = t.DoctorSTime,
                              DoctorCode = t.DoctorCode,
                              DoctorContent = t.DoctorContent,
                              DoctorETime = t.DoctorETime,
                              IsDelete = t.IsDelete,
                              BedCode = t.BedCode,
                              IsPublisher = t.IsPublisher,
                              PatientCode = t.PatientCode,
                              PatientName = p.Name
                          };
            dtoList = dtoList.WhereIF(!string.IsNullOrEmpty(patientName), o => o.PatientName.Contains(patientName));
            var response = WebResponseContent.Instance.OK("查询成功", dtoList);
            return response;
        }

        public async Task<WebResponseContent> UpdTell(TellModel tellModel)
        {
            int count = await _tellRepository.UpdateAsync(tellModel);
            if (count == 0)
            {
                var response = WebResponseContent.Instance.Error("修改失败");
                return response;
            }
            return WebResponseContent.Instance.OK("修改成功", count);
        }
    }
}



